package com.main.hotel.controller;
import com.alipay.api.internal.util.AlipaySignature;
import com.main.hotel.config.AlipayConfig;
import com.main.hotel.entity.Customer;
import com.main.hotel.entity.OrderInfo;
import com.main.hotel.service.CustomerService;

import com.main.hotel.service.RoomTypeService;
import com.main.hotel.service.impl.AliPayServiceImpl;
import com.main.hotel.util.OrderUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;

@Controller
public class MainController {
  @Autowired
  private CustomerService customerService;

  @Autowired
  private RoomTypeService roomTypeService;

  @RequestMapping("/index")//访问路径：http://localhost:8080/index
  public String index()
  {
    return "index";
  }
  @RequestMapping("/index2")//访问路径：http://localhost:8080/index
  public String index2()
  {
    return "index2";
  }
  @RequestMapping("/personal")//访问路径：http://localhost:8080/index

  public String personal()
  {
    System.out.println("999");
    return "personal";
  }
  @RequestMapping("/accounts")//访问路径：http://localhost:8080/index
  public String accounts()
  {
    return "accounts";
  }
  @RequestMapping("/update")//访问路径：http://localhost:8080/index
  public String update()
  {
    return "update";
  }
  @RequestMapping("/book")//访问路径：http://localhost:8080/book
  public String book()
  {
    return "book";
  }
  @RequestMapping("/signin")//访问路径：http://localhost:8080/signin
  public String signin()
  {
    return "signin";
  }
  @RequestMapping("/contact")//访问路径：http://localhost:8080/contact
  public String contact()
  {
    return "contact";
  }
  @RequestMapping("/rooms")//访问路径：http://localhost:8080/rooms
  public String rooms()
  {
    return "rooms";
  }

  @RequestMapping("/shortcodes")//访问路径：http://localhost:8080/shortcodes
  public String shortcodes()
  {
    return "shortcodes";
  }

  @RequestMapping("/gallery")//访问路径：http://localhost:8080/gallery
  public String gallery()
  {
    return "gallery";
  }

  @RequestMapping("/register")//访问路径：http://localhost:8080/register
  public String register()
  {
    return "register";
  }
  @RequestMapping("/success")//
  public String success()
  {
    return "success";
  }
  @RequestMapping("/test")//访问路径：http://localhost:8080/gallery
  public String test()
  {
    return "book_confirm";
  }
  @RequestMapping("/book_confirm")
  public String bookConfirm(OrderInfo orderInfo, Model model)
  {
    List<OrderInfo> orderList=new ArrayList<>();
    orderList.add(orderInfo);

    model.addAttribute("orderList",orderList);
    return "book_confirm";

  }
  @RequestMapping("/addCustomer")
  @ResponseBody
  public String addCustomer(Customer customer)
  {
    Date date=new Date();
    System.out.println(date.toString());
    customer.setCreate_date(date);
    int result=customerService.addCustomer(customer);
    if(result==1)
      return "true";
    else
      return "false";
  }

  @RequestMapping(value = "/returnUrl", method = RequestMethod.GET)
  public String returnUrl(HttpServletResponse response, HttpServletRequest request) throws Exception {
    return "paySuccess";
  }
}
